<script setup lang="ts">
import { useRouter } from 'vue-router'
import useUserStore from '@/stores/user'
import uiSubdomain from '@/constants/uiSubdomain'

const userStore = useUserStore()
const router = useRouter()

const loginUrl = uiSubdomain.LOGIN

window.addEventListener('message', (loginMessageRes) => {
  const { cmd, params } = loginMessageRes.data
  if (cmd === 'send_token' && params.isSuccess) {
    const userinfo = params.data
    const authentication = {
      expirationTime: params.expirationTime,
      expiresIn: params.expiresIn,
      refreshToken: params.refreshToken,
      token: params.token,
    }
    userStore.login(userinfo, authentication)
    router.push('/')
  }
})
</script>
<template>
  <div class="iframe-box">
    <iframe
      style="width: 100vw; height: 100vh; border: none"
      title="aws_login"
      :src="loginUrl"
    ></iframe>
  </div>
</template>
<style scoped lang="scss">
.iframe-box {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}
</style>
